package com.gjm.demo.controller;

import com.gjm.demo.service.TestService1;
import com.gjm.demo.service.TestService2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

@Controller
public class TestController {

    //属性注入
//    @Autowired
//    private TestService service;

//    private TestService service;
//
//    //无参构造函数
//    public TestController() {
//
//    }
//
//    //有参构造函数
//    public TestController(TestService service) {
//        this.service = service;
//    }

    //构造方法注入
//    private TestService1 service1;
//
//    private TestService2 service2;
//
//    public TestController() {
//
//    }
//
//    public TestController(TestService1 service1) {
//        this.service1 = service1;
//    }
//
//    public TestController(TestService2 service2) {
//        this.service2 = service2;
//    }
//
//    @Autowired
//    public TestController(TestService1 service1, TestService2 service2) {
//        this.service1 = service1;
//        this.service2 = service2;
//    }

    private TestService1 service1;

    private TestService2 service2;

    @Autowired
    public void setService1(TestService1 service1) {
        this.service1 = service1;
    }

    @Autowired
    public void setService2(TestService2 service2) {
        this.service2 = service2;
    }

    public void print() {
        System.out.println("controller");
        service1.print();
        service2.print();
    }
}
